package cn.hjh.dao;

import cn.hjh.pojo.House;
import cn.hjh.pojo.Users;
import org.hibernate.Query;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

public class HouseDao {
    /* 查询中关村地区面积大于80cm的房屋信息 */
    public List<House> findByHouse(){
        String hql = "from House where title like ? and floorage > ?";
        Query query = HibernateUtil.currentSession().createQuery(hql);
        query.setString(0,"%中关村%");
        query.setInteger(1,80);
        List<House> houseList = query.list();
        return houseList;
    }


    public List<House> findByHousePage(int pageNo, int pageSize){
        String hql = "from house where price = ? and title = ? and pubdate = ? and contact = ?";
        Query query = HibernateUtil.currentSession().createQuery(hql).setFirstResult((pageNo - 1) * pageSize).setMaxResults(pageSize);
        query.setInteger(0,80);
        query.setString(1,"学院路");
        try {
            query.setDate(2,new SimpleDateFormat("yyyy-MM-dd").parse("2019-11-21"));
        } catch (ParseException e) {
            e.printStackTrace();
        }
        query.setString(3,"123426932");
        List<House> houseList = query.list();
        return houseList;
    }

}
